const { cartFormatError } = require("../constant/err.type");

const validator = (rules) =>{
    //此处闭包是为了能够复用
    return async (ctx, next) => {
        try {
            ctx.verifyParams(rules);
        } catch (error) {
            console.error(error);
            cartFormatError.result = error;
            return ctx.app.emit("error", cartFormatError, ctx);
        }
    
        await next()
    }
}

module.exports = {
    validator,
}